const pagination = require('mongoose-sex-page');
const { Message } = require('../../model/message');
module.exports = async (req,res)=>{
  //已读
  if (req.body.state == 1){
    let page = req.query.page;
    let messages = await pagination(Message).find({state: 1}).page(page).size(10).display(3).populate('uid').exec();
    messages = JSON.stringify(messages);
    messages = JSON.parse(messages);
    res.render('admin/messageList',{
      messages
    });
  }
  //未读
  else if (req.body.state == 0){
    let page = req.query.page;
    let messages = await pagination(Message).find({state: 0}).page(page).size(10).display(3).populate('uid').exec();
    messages = JSON.stringify(messages);
    messages = JSON.parse(messages);
    res.render('admin/messageList',{
      messages
    });
  }
  //全部
  else{
    let page = req.query.page;
    let messages = await pagination(Message).find().page(page).size(10).display(3).populate('uid').exec();
    messages = JSON.stringify(messages);
    messages = JSON.parse(messages);
    res.render('admin/messageList',{
      messages
    });
  }
}